#ifndef _WDS_ENEMY_CRAFT_H_
#define _WDS_ENEMY_CRAFT_H_


#include "wds_lifeobject.h"
#include "wds_pickup.h"

#include "ui/ui_manager.h"

class WDSEnemy : public WDSLifeObject 
{
public:



	enum ENEMY_TYPES
	{
		ENEMY_TYPES_NONE,					
		ENEMY_TYPES_NORMAL,				

		ENEMY_TYPES_COUNT

	};

	enum ENEMY_SPAWN_TYPE
	{
		ENEMY_SPAWN_TYPE_NONE,
		ENEMY_SPAWN_TYPE_OFFSCREEN,
		ENEMY_SPAWN_TYPE_GROUND,
		ENEMY_SPAWN_TYPE_EATING,
		ENEMY_SPAWN_TYPE_C,
	};

	enum ENEMY_STATES
	{
		ENEMY_STATES_NONE,

		ENEMY_STATES_GETHIT_START,
		ENEMY_STATES_GETHIT,		
		ENEMY_STATES_GETHIT_END,

		ENEMY_STATES_GETHIT_CRAWL_START,
		ENEMY_STATES_GETHIT_CRAWL,
		ENEMY_STATES_GETHIT_CRAWL_END,

		ENEMY_STATES_CHASE_BEFORE_START,
		ENEMY_STATES_CHASE_BEFORE,		// just smooth animation
		ENEMY_STATES_CHASE_START,	
		ENEMY_STATES_CHASE,	

		ENEMY_STATES_CHASE_lUNATIC_START,
		ENEMY_STATES_CHASE_lUNATIC,
		ENEMY_STATES_CHASE_lUNATIC_PAUSE,

		ENEMY_STATES_GETHIT_TO_CRAWL_START,
		ENEMY_STATES_GETHIT_TO_CRAWL_GETHIT_START,
		ENEMY_STATES_GETHIT_TO_CRAWL_GETHIT,
		ENEMY_STATES_GETHIT_TO_CRAWL_CRAWL_BEFORE_START,
		ENEMY_STATES_GETHIT_TO_CRAWL_CRAWL_BEFORE,
		ENEMY_STATES_GETHIT_TO_CRAWL_END,

		ENEMY_STATES_CHASE_CRAWL_START,
		ENEMY_STATES_CHASE_CRAWL,
		ENEMY_STATES_CHASE_CRAWL_PAUSE,

		ENEMY_STATES_ATTACK_START,
		ENEMY_STATES_ATTACK,
		ENEMY_STATES_ATTACK_END,
		
		ENEMY_STATES_DYING_START,
		ENEMY_STATES_DYING,
		ENEMY_STATES_DYING_END,
		ENEMY_STATES_DEAD,

		ENEMY_STATES_DYING_CRAWL_START,
		ENEMY_STATES_DYING_CRAWL,
		ENEMY_STATES_DEAD_CRAWL,

		ENEMY_STATES_RISE_START,
		ENEMY_STATES_RISE,
		ENEMY_STATES_RISE_END,

		ENEMY_STATES_EATING_INIT,
		ENEMY_STATES_EATING_START,
		ENEMY_STATES_EATING,
		ENEMY_STATES_EATING_END,

		ENEMY_STATES_EATING_STANDUP_START,
		ENEMY_STATES_EATING_STANDUP,
		ENEMY_STATES_EATING_STANDUP_END,

		ENEMY_STATES_EATING_SITDOWN_START,
		ENEMY_STATES_EATING_SITDOWN,
		ENEMY_STATES_EATING_SITDOWN_END,

		ENEMY_STATES_IDLE_START,
		ENEMY_STATES_IDLE,
		ENEMY_STATES_IDLE_END,
		ENEMY_STATES_READYSPAWN,

		ENEMY_STATES_COUNT

	};

	
	WDSEnemy(ENEMY_TYPES EnemyType);
	
	virtual void							Render(const math::Vec2& Offset, float Scale);
	virtual void							Tick(	float dt,
													float GameDifficulty,
													float PlayerReflex,
													const math::Vec2& Offset);

	virtual void									ReSpawn();
	virtual bool							IsReadyToSpawn() const { return (m_EnemyState == ENEMY_STATES_READYSPAWN); };
	

	void									InitSpawning(
													float Dealy,									
													WDSPickup::PICKUP_TYPES PickupType,
													ENEMY_SPAWN_TYPE SpawnType,
													const math::Vec2& Offset
													);

	void									RenderShadow(const math::Vec2& Offset, float Scale);
	
	static std::string						MapTypeToName(ENEMY_TYPES Type);
	static ENEMY_TYPES						MapNameToType(const std::string& Name);
		
	static std::string						MapTypeToBoneFile(ENEMY_TYPES Type);
	const ENEMY_TYPES						GetEnemeyType() const { return m_EnemyType; };	
	bool									HitTest(WDSBullet* pBullet);
	void									AddForce(const math::Vec2& Dir,float Duration, float Accel) { m_Movement.AddForce(Dir, Duration, Accel); };
	bool									GetIsCrawl() const { return m_IsCrawl; };
	WDSEnemy::ENEMY_STATES					GetEnemeyState() const { return m_EnemyState; };
	
protected:

	virtual void							OnDie();

	void									Tick_States(float dt, const math::Vec2& Offset);
	void									Tick_Idle(float dt, const math::Vec2& Offset);
	void									Tick_Wander(float dt, const math::Vec2& Offset);
	void									Tick_Chase(float dt, const math::Vec2& Offset);
	
	void									Turn(float Degree);
	void									AvoidMovement(float Degree);
	void									CheckAttackHit(float Scale);

	void									CheckSurrounding(const math::Vec2& Offset);
	bool									IsNearScreen(const math::Vec2& Offset);	
	bool									IsOtherEnemyInThatDegree(float Degree, float Dist, bool TestDraw);
	void									SetAnimation(const std::string& Name);
	
	float									m_DelaySpawn;
	WDSPickup::PICKUP_TYPES					m_SpawnPickup;
	bool									m_IsBoss;
	ENEMY_TYPES								m_EnemyType;
	ENEMY_STATES							m_EnemyState;

	float									m_Speed;
	float									m_SpeedScale;
	float									m_TurnSpeed;
	float									m_NextTurnDelay;	
	std::vector<WDSEnemy*>					m_Neibhours;
	float									m_NextMovementTargetDealy;

	math::Vec2								m_TestOffset;
	COLOR									m_TestColor;

	float									m_NextStateDelay;
	float									m_AttackHalfTime;
	float									m_AttackDamage;
	bool									m_IsLunatic;
	bool									m_IsCrawl;
	int										m_EatCurrentLoop;
	int										m_EatMaxLoop;
	std::string								m_Prefix;
	std::string								m_CurrentAnimation;

};

#endif
